package pack4;

class Solution4 {
    public String removeStars(String s) {
        StringBuilder result = new StringBuilder();

        for (char c : s.toCharArray()) {
            if (c == '*') {
                if (result.length() > 0) {
                    result.deleteCharAt(result.length() - 1);
                }
            } else {
                result.append(c);
            }
        }

        return result.toString();
    }

    public static void main(String[] args) {
        Solution4 solution = new Solution4();
        System.out.println(solution.removeStars("\""+"leet**cod*e"+"\""));
        System.out.println(solution.removeStars("\""+"erase*****"+"\""));
    }
}